﻿using SIG.Core;
using SIG.Resources.Admin;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;

namespace SIG.Model.Case
{
    public partial class Work : AuditableEntity<int>
    {
        public Work()
        {
            EntityName = EntityNames.Work;
            this.WorkTypes = new List<WorkType>();
        }

        [Display(Name = "主题", Prompt = "主题")]
        [Required(ErrorMessage = "请输入主题")]
        public string Title { get; set; }
     

        [Display(Name = "完成年份", Prompt = "完成年份")]
        [Required(ErrorMessage = "请输入排序")]
        [RegularExpression(@"^-?\d*$", ErrorMessage = "格式不正确")]
        public int FinishYear { get; set; }


        [Display(Name = "描述", Prompt = "描述")]
        public string Abstract { get; set; }

        [Display(Name = "内容", Prompt = "内容")]
        public string Body { get; set; }

        [Display(Name = "显示", Prompt = "显示")]
        public int ViewCount { get; set; }
         [Display(Name = "缩略图", Prompt = "缩略图")]
        public string Thumbnail { get; set; }
         [Display(Name = "大图", Prompt = "大图")]
        public string ImageUrl { get; set; }
         [Display(Name = "网址", Prompt = "网址")]
         [Url(ErrorMessage = "网址格式不正确")]
        public string  Demourl { get; set; }
         [Display(Name = "推荐", Prompt = "推荐")]
        public bool Recommend { get; set; }
         [Display(Name = "激活", Prompt = "激活")]
        public bool Active { get; set; }          
        public string TypeIds { get; set; }
        [Display(Name = "案例分类")]
        public string[] WorkTypesIds { get; set; }

        public virtual ICollection<WorkType> WorkTypes { get; set; } = new HashSet<WorkType>();

        public string ClassName
        {
            get
            {
                if (string.IsNullOrEmpty(this.TypeIds)) return string.Empty;
                var q = (from i in this.TypeIds.Split(',')
                    select $"cate{i}").ToArray();
                return string.Join(" ", q);
            }


        }
        public int SolutionId { get; set; }
        public virtual Solution Solution { get; set; }
        public string SolutionTitle => this.Solution != null ? this.Solution.Title : string.Empty;

        public int? ClientId { get; set; }
        public virtual Client Client { get; set; }
        public string ClientName => this.Client != null ? this.Client.ClientName : string.Empty;

        
    }
}
